<?php
/**
 * 厅主管理-域名管理
 * User: Tommy
 * Date: 2018/11/9
 * Time: 16:18
 */

namespace App\Controllers;


use App\Services\DomainManageService;
use common\enum\CommonEnum;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;

class DomainManageController extends BaseController
{
    /**
     * 获取厅主列表
     * @param Request $request
     * @return array
     * @throws \Illuminate\Validation\ValidationException
     */
    public function getList(Request $request)
    {
        $this->validate($request, [
            'hall_id' => 'integer',
            'status'  => [Rule::in([CommonEnum::DISABLE, CommonEnum::ENABLED])],
            'page'    => 'integer',
            'size'    => 'integer',
        ]);
        $value = $request->input();
        return DomainManageService::domainList($value);
    }

    /**
     * 添加域名
     * @param Request $request
     * @return mixed
     * @throws \App\Exceptions\CustomException
     * @throws \Illuminate\Validation\ValidationException
     */
    public function addDomain(Request $request)
    {
        $this->validate($request, [
            'hall_id' => 'required|integer',
            'domain'  => 'required',
        ]);
        $value = $request->input();
        return DomainManageService::addDomain($value);
    }

    /**
     * 域名启/停
     * @param Request $request
     * @return mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    public function updateStatus(Request $request)
    {
        $this->validate($request, [
            'domain_id' => 'required|integer',
            'status'    => ['required', Rule::in(CommonEnum::ENABLED, CommonEnum::DISABLE)]
        ]);
        $id     = $request->input('domain_id');
        $status = $request->only('status');
        return DomainManageService::updateStatus($id, $status);
    }

    /**
     * 修改域名
     * @param Request $request
     * @return mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    public function updateDomain(Request $request)
    {
        $this->validate($request, [
            'domain_id' => 'required|integer',
            'domain'   => 'required',
        ]);
        $id     = $request->input('domain_id');
        $domain = $request->only('domain');
        return DomainManageService::updateDomain($id, $domain);
    }


}